using System;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Services;
using Volo.Abp.Users;

namespace Acme.BookStore.FormWhx.Storehouse
{
    public class WarehouseOperationLogService : DomainService, IWarehouseOperationLogService
    {
        private readonly IRepository<WarehouseOperationLog, Guid> _operationLogRepository;
        private readonly ICurrentUser _currentUser;

        public WarehouseOperationLogService(
            IRepository<WarehouseOperationLog, Guid> operationLogRepository,
            ICurrentUser currentUser)
        {
            _operationLogRepository = operationLogRepository;
            _currentUser = currentUser;
        }

        public async Task LogOperationAsync(
            string operationType,
            string description,
            Guid warehouseId,
            string warehouseCode,
            string warehouseName)
        {
            var operationLog = new WarehouseOperationLog(
                GuidGenerator.Create(),
                operationType,
                _currentUser.UserName ?? "System",
                description,
                warehouseId,
                warehouseCode,
                warehouseName
            );

            await _operationLogRepository.InsertAsync(operationLog);
        }
    }
} 